package com.ftg.learn.controller;

import com.ftg.learn.chapter01.Linked;
import com.ftg.learn.domain.EmployeeDomain;
import com.ftg.learn.service.EmployeeService;
import com.ftg.learn.util.R;
import com.ftg.learn.util.TipUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * hello
 * RestController  控制层 协议(接收前台参数，处理，返回信息前端)
 *
 * @author 布衣
 */
@RestController
@Api(tags = "员工功能列表清单")
public class EmployeeController {

    @Resource
    EmployeeService employeeService;

    /**
     * getmapping  web采用get请求来完成操作
     * method : get 查询  post 添加 put 修改 delete 删除 head trace options
     *
     * @return
     */
    @GetMapping("/employee/list")
    @ApiOperation(value = "返回员工的全部信息")
    public R<PageInfo<EmployeeDomain>> list(
            @RequestParam(value = "pageNum") Integer pageNum,
            @RequestParam(value = "pageSize") Integer pageSize,
            @RequestParam(value = "ename", required = false) String ename
    ) {
        return R.build(TipUtil.LIST_SUCCESS, employeeService.list(ename, pageNum, pageSize));
    }

    @PostMapping("/employee/save")
    public R<Integer> save(@RequestBody EmployeeDomain employeeDomain) {
        System.out.println(employeeDomain);
        return R.build(TipUtil.ADD_SUCCESS, employeeService.save(employeeDomain));
    }

}
